package com.zzyy.dtx.msg.handle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class MsgHandler
{

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @Value("${mq.msg.exchange}")  //yml文件配置mq.msg.exchange=msg.exchange
    private String exchange;

    /**
     * @param routingkey    常量MQ_ORDER_ROUTING_KEY = "order.routing.key";
     * @param jsonMsg       jsonMsg 消息内容
     */
    public void send(String routingkey,String jsonMsg) {
        log.info("exchange:{}",this.exchange);
        log.info("routingkey:{}",routingkey);
        log.info("jsonMsg:{}",jsonMsg);
        this.rabbitTemplate.convertAndSend(this.exchange,routingkey, jsonMsg);
        log.info("MsgHandler和MQ通信结果1:{}","----------come here over");
        System.out.println();
    }
}
